﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace ClientSocketTest
{
    public partial class ClientControlMainForm : Form
    {
        ClientSocket gClientSocket;

        public ClientControlMainForm()
        {
            InitializeComponent();

            gClientSocket = new ClientSocket();
            gClientSocket.setInformLoger(informMessage);
        }
        private void informMessage(string infor)
        {
            InformationControl.Messages(Inform_richTextBox, InformationControl.MsgType.Incoming, infor + Environment.NewLine);
        }

        private void Clear_Message_button_Click(object sender, EventArgs e)
        {
            InformationControl.MsgClear(Inform_richTextBox);
        }

        private void Test_button_Click(object sender, EventArgs e)
        {
            InformationControl.Messages(Inform_richTextBox, InformationControl.MsgType.Incoming, "test======" + Environment.NewLine);
        }

        private void Connect_button_Click(object sender, EventArgs e)
        {
            IPAddress ipAddress = Dns.Resolve("localhost").AddressList[0];
            informMessage("ipAddress : " + ipAddress.ToString());
            gClientSocket.Connect(ipAddress.ToString(), 80);
            Send_button.Enabled = true;
        }

        private void Send_button_Click(object sender, EventArgs e)
        {
            gClientSocket.SendMessageString(Send_textBox.Text);
        }

        private void Disconnect_button_Click(object sender, EventArgs e)
        {
            gClientSocket.CloseConnection();
        }
    }//public partial class ClientControlMainForm : Form
}//namespace ClientSocketTest
